package day4;

import java.util.ArrayList;
import java.util.Scanner;

import org.junit.Test;

import day4.Student;

public class demo1 {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量：");
		Integer count = scanner.nextInt();
	    //int[] array = new int[count];
		ArrayList<Student> list = new ArrayList<Student>();
		//Student[] students = new Student[count];
		for (;;) {
			System.out.println("请输入id：");
			Integer id = scanner.nextInt();
			System.out.println("请输入名字：");
			String name = scanner.next();
			System.out.println("请输入年龄：");
			Integer age = scanner.nextInt();
			System.out.println("请输入班级名字：");
			String className = scanner.next();
			
			Student student = new Student( id, age, name, className);
			// 每次循环构造一个Student对象
			//student.setId(id);;
			//student.setName(name);;
			//student.setAge(age);;
			//student.setClassName(className);
			// 把构造的学生对象放到指定下标位置
			list.add(student);
			System.out.println("退出请输入0");
			Integer quit = scanner.nextInt();
			if(quit == 0) {
				break;
		}
		}
		System.out.println("-----------------------");
		for (Student student : list) {
			
		
			//Student student = students[i];
//			System.out.println(student.id);
//			System.out.println(student.name);
//			System.out.println(student.age);
//			System.out.println(student.className);
			//System.out.println(student.toString());
			System.out.println(student);
		}
		System.out.println("-----------------------");
		
		while (true) {
			System.out.println("根据id查找输入：1");
			System.out.println("根据name查找输入：2");
			System.out.println("根据age查找输入：3");
			System.out.println("根据className查找输入：4");
			System.out.println("退出：0");
			Integer type = scanner.nextInt();
			if (type == 0) {
				System.out.println("退出搜索");
				break;
			}
			
			switch (type) {
			case 1: // 根据id查找
				System.out.println("请输入要查找的学生id：");
				
				// 根据id查找到了没有
				// boolean isExistId = false;
				boolean isSearchByIdFind = false;
				for (Student student : list) {
					Integer id = scanner.nextInt();
					if (student.getId() == id) {
						isSearchByIdFind = true;
						System.out.println(student);
					}
				}
				// 如果遍历完了还是false，证明没有该信息学生
				if (isSearchByIdFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 2: // 根据name查找
				System.out.println("请输入要查找的名字：");
				
				boolean isSearchByNameFind = false;
				for (Student student : list) {
					String name = scanner.next();
					// 判断字符串的内容是不是相等，不能用==，要是用equals()方法
					if (name.equals(student.getName())) {
						isSearchByNameFind = true;
						System.out.println(student);
					}
				}
				if (isSearchByNameFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 3: // 根据age查找
				System.out.println("请输入要查找的学生age：");
				Integer age = scanner.nextInt();
				// 根据age查找到了没有
				boolean isSearchByAgeFind = false;
				for (Student student : list) {
					//Student student = students[i];
					if (student.getAge() == age) {
						isSearchByAgeFind = true;
						System.out.println(student);
					}
				}
				// 如果遍历完了还是false，证明没有该信息学生
				if (isSearchByAgeFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 4: // 根据classNmae查找
				System.out.println("请输入需要查找的学生班级: ");
				String className = scanner.next();
				boolean isSearchByClassNameFind = false;
				for (Student student : list) {
					if (student.getClassName().equals(className)) {
						isSearchByClassNameFind = true;	
						System.out.println(student);
					}
				}
				if (isSearchByClassNameFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			default:
				break;
			}
			
		}
		
		
	}
	
	
	
	
}
